package com.gufe.service.user.impl.mp.quiz;

import com.gufe.entity.wxUsers;
import com.gufe.mapper.user.mp.UserMapper;
import com.gufe.mapper.user.mp.quiz.WxUserMapper;
import com.gufe.service.user.mp.quiz.LeaderboardService;
import com.gufe.vo.quiz.LeaderboardUserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class LeaderboardServiceImpl implements LeaderboardService {

    @Autowired
    private WxUserMapper wxUserMapper;

    @Override
    public List<LeaderboardUserVO> getLeaderboard() {
        List<wxUsers> users = wxUserMapper.findAllOrderByTotalPointsDesc(); // 假设你的 UserMapper 有这个方法
        List<LeaderboardUserVO> leaderboard = new ArrayList<>();
        int rank = 1;
        for (wxUsers user : users) {
            LeaderboardUserVO vo = new LeaderboardUserVO();
            vo.setUserId(user.getId());
            vo.setNickname(user.getNickName());
            vo.setAvatarUrl(user.getAvatarUrl());
            vo.setTotalPoints(user.getTotalPoints());
            vo.setRank(rank++);
            leaderboard.add(vo);
        }
        return leaderboard;
    }
}